/**
 * @file xtimer.h
 * @author eric
 * @brief
 * @version 0.1
 * @date 2022-04-16
 *
 * @copyright Copyright (c) 2022
 *
 */

#ifndef _XTIMER_H
#define _XTIMER_H

#include "dlist.h"
#include <stdint.h>

enum option
{
	XTIMER_SINGLE = 0,
	XTIMER_REPEAT,
};

typedef struct list_node
{
	const char *name;
	uint32_t timout;
	uint32_t start;
	void *arg;
	void (*callback)(void *arg);
	int opt;

	struct list_head list;
} list_node_t, xtimer_t;

/**
 * @brief start or restart a xtimer
 *
 * @param timer
 * @return int
 */
int xtimer_start(xtimer_t *timer);

/**
 * @brief stop a xtimer
 *
 * @param timer
 * @return int 0:ok other:err
 */
int xtimer_stop(xtimer_t *timer);

/**
 * @brief Query timer is valid???
 *
 * @param timer
 * @return int 0:vaild, other:invalid
 */
int xtimer_isvalid(xtimer_t *timer);

/**
 * @brief get the timer remain ticks
 *
 * @param timer
 * @return int -1:err, other:remain ticks
 */
int xtimer_remain(xtimer_t *timer);

/**
 * @brief put to main while(1)
 *
 */
void xtimer_loop(void);

/* Get current tick, eg.HAL_GetTicks() */
#ifndef xtimer_get_tick
#define xtimer_get_tick() HAL_GetTick()
#endif // !xtimer_get_tick

#endif // !_XTIMER_H
